package com.example.mybatis_plus.blog.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.mybatis_plus.blog.entity.User;
import com.example.mybatis_plus.blog.mapper.UserMapper;
import com.example.mybatis_plus.blog.vo.CommonResult;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sCrazy
 * @since 2021-03-15
 */
@Slf4j
@Controller
public class UserController {

    @Resource
    UserMapper userMapper;


    @GetMapping("/hello")
    @ResponseBody
    public CommonResult hello(){
        User user = userMapper.
                selectOne(new QueryWrapper<User>().eq("id", 1373929247646937090L));
        return CommonResult.ok().data("user",user);
    }

    @GetMapping("/go")
    public String goTOHello(Model model){
        model.addAttribute("msg","hello Swagger!!");
        return "forward:/hello";
    }

    @ResponseBody
    @GetMapping("/get/{id}")
    public CommonResult findById(@PathVariable Long id){
        User user = userMapper.findByKKId(id);
        return CommonResult.ok().data("user",user);
    }

}

